Excel BI - Excel Challenge 718

excel-challenges
excel-formulas
🔰 Remove Nth digit and see if remaining number is perfectly divisible by this Nth digit.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 718

Challenge Description

🔰 Remove Nth digit and see if remaining number is perfectly divisible by this Nth digit. If this happens for all digits, then list first 10000 such numbers starting with double digit numbers. If number contains 0, ignore the number.

Solutions

library(data.table)
library(tidyverse)
library(readxl)

path = "Excel/700-799/718/718 Divisible by All Digits.xlsx"
test = read_excel(path, range = "A1:A10001")


dt = data.table(n = 10:1e7)
dt[, char := as.character(n)]
dt = dt[!grepl("0", char)]  

passes_divisibility_rule = function(number_str) {
  digits = as.integer(strsplit(number_str, "")[[1]])
  len = length(digits)

  for (i in seq_len(len)) {
    removed = digits[i]
    if (removed == 0) return(FALSE)

    remaining_digits = digits[-i]
    remaining_number = as.integer(paste0(remaining_digits, collapse = ""))

    if (remaining_number %% removed != 0) {
      return(FALSE)
    }
  }

  return(TRUE)
}

dt[, valid := vapply(char, passes_divisibility_rule, logical(1))]

result = dt[valid == TRUE, .(n)]
result = result[1:10000]

all.equal(result, test, check.attributes = FALSE)
# [1] TRUE
  • Logic: Read the workbook ranges needed for the challenge; Iterate through the sequence until the rule is satisfied.
  • Strengths: The algorithm is explicit about the sequence rule, so the control flow is easy to validate against the prompt.
  • Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
  • Gem: The non-obvious part is the local rule inside the loop, because that rule determines the whole output.
import pandas as pd
import numpy as np

path = "700-799/718/718 Divisible by All Digits.xlsx"
test = pd.read_excel(path, usecols="A", nrows=10001)

numbers = np.arange(10, 10_000_001)
numbers_str = numbers.astype(str)

mask_no_zero = np.char.find(numbers_str, '0') == -1
filtered_numbers = numbers[mask_no_zero]
filtered_numbers_str = numbers_str[mask_no_zero]

def passes_divisibility_rule(number_str):
    digits = [int(d) for d in number_str]
    for i in range(len(digits)):
        removed = digits[i]
        if removed == 0:
            return False
        remaining_digits = digits[:i] + digits[i+1:]
        if not remaining_digits:
            continue
        remaining_number = int(''.join(map(str, remaining_digits)))
        if remaining_number % removed != 0:
            return False
    return True

valid = [passes_divisibility_rule(s) for s in filtered_numbers_str]
result = pd.DataFrame({'Numbers': filtered_numbers})[valid].head(10000).reset_index(drop=True)

print(result.equals(test)) # True

The Python version keeps the algorithm explicit, which helps when the challenge depends on a greedy or iterative rule.

Difficulty Level

Easy / Medium

The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.